<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: ZLF
  Date: 2020/11/12
  Time: 21:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="UTF-8">
<head>
<%@ include file="include-head.jsp" %>
<title>众筹网</title>
<script type="text/javascript">
    $(function(){
        //调用函数初始化导航条
        initPagination();
    });
    //声明初始化函数
    function initPagination() {
        //获取分页的总记录数
        var totalRecord = ${pageInfo.total};
        var properties = {
            num_edge_entries: 1,           //边缘页数
            num_display_entries: 4,        //主体页数
            callback: pageSelectCallback,     //用户点击“翻页”按钮的执行翻页操作的回调函数
            current_page: ${pageInfo.pageNum-1},   //当前页，pagenum从1开始，必须-1后才可以赋值
            items_per_page: ${pageInfo.pageSize},    //每页显示条数
            prev_text: "上一页",
            next_text: "下一页"
        };
        //调用分页导航条对应的jquery对象的pagination（）方法生成导航条
        $("#Pagination").pagination(totalRecord, properties);
    }
    //翻页的回调函数
    //pageIndex表示用户在页面上点击的页码数值
    function pageSelectCallback(pageIndex, jQuery) {
        //pagename比pageindex大1
        var pageNum = pageIndex + 1;
        //执行页面跳转
        window.location.href = "/admin/page?pageNum=" + pageNum + "&keyword=${param.keyword}";
        //取消超链接的默认行为
        return false;
    }
    $(function () {
        //全选设置
        $("#summaryBox").click(function () {
            var currencyStatus = this.checked;
            $(".itemBox").prop("checked", currencyStatus);
        });
        //手动全选时全选框自动打勾
        $("#adminPageBody").on("click", ".itemBox", function() {
            var checkedBoxCount = $(".itemBox:checked").length;
            var totalBoxCount = $(".itemBox").length;
            $("#summaryBox").prop("checked", checkedBoxCount == totalBoxCount);
        });
        //生成adminList
        $("#removeAll").click(function () {
            window.adminList=[];
            $(".itemBox:checked").each(function () {
                var id=this.id;
                 adminList.push(id);
            });
            var pageNum="${pageInfo.pageNum}";
            var keyword="${param.keyword}";
            this.href="admin/remove/all?adminList="+adminList+"&pageNum="+pageNum+"&keyword="+keyword;
        })
    });

</script>
</head>
<body>

<%@ include file="include-nav.jsp" %>
<div class="container-fluid">
    <div class="row">
        <%@include file="include-sidebar.jsp" %>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form action="admin/page" method="post" class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input name="keyword" class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询
                        </button>
                    </form>
                    <a  id="removeAll" type="button" class="btn btn-danger" style="float:right;margin-left:10px;"><i
                            class=" glyphicon glyphicon-remove"></i> 删除
                    </a>
                    <a href="admin/to/add/page" class="btn btn-primary" style="float:right;"
                            onclick="window.location.href='add.html'"><i class="glyphicon glyphicon-plus"></i> 新增
                    </a>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th width="30"><input id="summaryBox" type="checkbox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody id="adminPageBody">
                            <c:if test="${empty pageInfo.list}">
                                <tr>
                                      <td colspan="6">抱歉！没有查询到相关数据</td>
                                </tr>
                            </c:if>
                            <c:if test="${!empty pageInfo.list}">
                                <c:forEach items="${pageInfo.list}" var="admin" varStatus="myStatus">
                                    <tr>
                                        <td>${myStatus.count}</td>
                                        <td><input id="${admin.id}" class="itemBox" type="checkbox"></td>
                                        <td>${admin.loginAcct}</td>
                                        <td>${admin.userName}</td>
                                        <td>${admin.email}</td>
                                        <td>
                                            <a href="assign/to/role/page?adminId=${admin.id}&pageNum=${pageInfo.pageNum}&keyword=${param.keyword}" type="button" class="btn btn-success btn-xs"><i
                                                    class=" glyphicon glyphicon-check"></i></a>
                                            <a href="admin/to/edit/page?adminId=${admin.id}&pageNum=${pageInfo.pageNum}&keyword=${param.keyword}" type="button" class="btn btn-primary btn-xs"><i
                                                    class=" glyphicon glyphicon-pencil"></i></a>
                                            <a href="admin/remove/${admin.id}/${pageInfo.pageNum}/${param.keyword}" class="btn btn-danger btn-xs"><i
                                                    class=" glyphicon glyphicon-remove"></i></a>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" align="center">
                                    <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
